package com.agent.user.mapper;

import com.agent.feign.entity.Member;
import com.agent.user.dto.UserLoginDTO;
import com.agent.user.entity.Code;
import com.agent.user.param.UserLoginParam;
import com.agent.user.param.UserParam;
import jakarta.validation.constraints.NotBlank;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;

public interface UserMapper {
    @Select("select count(*) from user where email = #{email}")
    int countByMail(@NotBlank(message = "邮箱不能为空! ") String mail);

    @Select("select count(*) from user where userId = #{userId}")
    int countByUserId(@NotBlank(message = "用户id不能为空! ") String userId);

    @Select("select password from user where userId = #{userId}")
    String getPasswordByUserId(@NotBlank(message = "用户id不能为空! ") String userId);

    @Select("select password from user where email=#{email}")
    String getPasswordByEmail(@NotBlank(message = "邮箱不能为空! ") String email);

    @Select("select userName from user where userId = #{userId}")
    String getName(@NotBlank(message = "用户id不能为空! ")String userId );

    @Select("select role from user where userId = #{userId}")
    String getRole(@NotBlank(message = "用户id不能为空! ")String userId);

    @Insert("insert into user(userId,userName,email,password,gender,avatar,role) values(#{userId},#{userName},#{email},#{password},#{gender},#{avatar},#{role})")
    void insertUser(UserParam user);

    @Select("select id,userId,userName,avatar,id,role from user where (userId=#{userId} or email=#{email}) and password= #{password} ")
    UserLoginDTO LoginByPassword(UserLoginParam loginParam);

    @Select("select id,userId,userName,avatar,id,role from user where email=#{email}")
    UserLoginDTO LoginByCode(UserLoginParam userLoginParam);

    @Select("select * from code where CodeUrl=#{CodeUrl}")
    Code getCode(String CodeUrl);

    @Select("select userId,userName,avatar,role from user where userId=#{userId}")
    Member getMember(String userId);

    @Select("select userId from user where email=#{email}")
    String getUserIdByEmail(String email);
}
